import datetime
import os.path
import sys

from selenium import webdriver
from selenium.webdriver.ie.service import Service
from webdriver_manager.chrome import ChromeDriverManager


class Driver:
    driver = ""
    def __init__(self):
        options = webdriver.ChromeOptions()
        #options.add_argument("-headless")
        self.driver=webdriver.Chrome(service=Service(ChromeDriverManager().install()),options=options)
    def getScreeShot(self):
        #创建屏幕截图
        #图片文件名按照：年月日时分秒来显示（./2025-05-25-154356.png）文件名称
        #图片保存路径：../images/调用方法-2025-05-25/2025-05-25-154356.png
        dirname=datetime.datetime.now().strftime("%Y-%m-%d")
        #判断文件路径是否存在
        #../images/2025-05-25
        if not os.path.exists("../images/"+dirname):
            os.mkdir("../images/"+dirname)
        #2025-05-25-154356png
        filename=sys._getframe().f_back.f_code.co_name+datetime.datetime.now().strftime("%Y-%m_%d-%H%M%S")+".png"
        self.driver.save_screenshot("../images/"+dirname+"/"+filename)


BlogDriver = Driver()